package c.h.a.m0.s;

import android.annotation.TargetApi;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraManager.TorchCallback;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import java.util.Objects;

@TargetApi(23)
/* compiled from: TorchControlM */
public class e extends a {
    public a e;

    /* compiled from: TorchControlM */
    public class a extends TorchCallback {
        public Handler a = new Handler(Looper.getMainLooper());

        public void onTorchModeChanged(String str, boolean z) {
            if ((TextUtils.equals(str, e.this.b) ^ 1) == 0) {
                e.this.f(z);
                e.this.e(true);
            }
        }

        public void onTorchModeUnavailable(String str) {
            if ((TextUtils.equals(str, e.this.b) ^ 1) == 0) {
                e.this.e(false);
            }
        }
    }

    public e(CameraManager cameraManager) {
        this.a = cameraManager;
        this.b = c(cameraManager);
        a aVar = new a();
        this.e = aVar;
        this.a.registerTorchCallback(aVar, aVar.a);
    }

    public void a() {
        if (!TextUtils.isEmpty(this.b) && d()) {
            try {
                this.a.setTorchMode(this.b, false);
            } catch (Exception unused) {
            }
        }
    }

    public void b() {
        if (!TextUtils.isEmpty(this.b) && !d()) {
            try {
                this.a.setTorchMode(this.b, true);
            } catch (Exception unused) {
            }
        }
    }

    public void release() {
        a aVar = this.e;
        if (aVar != null) {
            CameraManager cameraManager = this.a;
            Objects.requireNonNull(aVar);
            cameraManager.unregisterTorchCallback(aVar);
            this.a = null;
            this.e = null;
        }
    }
}
